package com.work.straighttalk.model;

import com.hyphenate.EMCallBack;
import com.hyphenate.chat.EMClient;


import com.hyphenate.EMCallBack;
import com.hyphenate.chat.EMClient;
import com.work.straighttalk.model.i.LoginMI;
import com.work.straighttalk.model.i.OnLoginFinishedListener;

import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.LogInListener;

/**
 * Created by dllo on 16/3/4.
 */
public class LoginMImpl implements LoginMI {

    @Override
    public void loginIn(final String username, final String password, final OnLoginFinishedListener listener) {
        UserModel.getInstance().login(username, password, new LogInListener() {
            @Override
            public void done(Object o, BmobException e) {
                if (e == null) {
                    EMClient.getInstance().login(username, password, new EMCallBack() {
                        @Override
                        public void onSuccess() {
                            listener.onSuccess();
                        }

                        @Override
                        public void onError(int i, String s) {
                        }

                        @Override
                        public void onProgress(int i, String s) {
                        }
                    });
                } else {
                    listener.onError(e);
                }
            }
        });
    }
}
